/* 
 * Copyright (C) 2008 anphoralhrod.blogspot.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received Oi copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * betCalc.java
 *
 * Created on 14 de julio de 2008, 11:48
 */
package betcalc;

/**
 *
 * @author lhrod
 */
public class betCalc {

    private float Oi, Of, Si, Sf, Pt;
    private float Pi, Pf;
    private float Li;
    private boolean correct = false;

    /**
     * @return the Li
     */
    public float getLi() {
        return Li;
    }

    public enum TCalc {

        BACKBACK, BACKLAY, LAYBACK, BACKBACKINV
    }
//    public final static int BACKBACK = 0;
//    public final static int BACKLAY = 1;
//    public final static int BACKLAY = 1;
//    public final static int BACKLAY = 1;

    public betCalc(float Oi, float Si, float Pt, TCalc tipo) {
        correct = (Oi > 0) && (Pt > 0) && (Si > 0);
        if (!correct) {
            return;
        }
        this.Oi = Oi;
        this.Si = Si;
        this.Pt = Pt;
        switch (tipo) {
            case BACKBACK:
                Pi = (Oi - 1) * Si;
                Sf = Pi - Pt;
                Of = ((Pt + Si) / Sf) + 1;
                correct = correct && (Of > 1.01) && (Sf > 0);
                if (!correct) {
                    return;
                }
                Pf = (Of - 1) * Sf;
                break;
            case BACKLAY:
                Sf = Pt + Si;
                Of = (Oi * Si) / Sf;
                correct = correct && (Of > 1.01) && (Sf > 0);
                if (!correct) {
                    return;
                }
                Pi = (Oi - 1) * Si;
                Pf = Sf;
                break;
            case LAYBACK:
                Li = (Oi - 1) * Si;
                Pi = Si;
                Sf = Pi - Pt;
                float Lf = Sf;
                Pf = Pt + Li;
                Of = (Pf / Sf) + 1;
                correct = correct && (Of > 1.01) && (Sf > 0);
                if (!correct) {
                    return;
                }
                break;
        }
        Of = Math.round(Of * 100) / (float) 100;
        Sf = Math.round(Sf * 100) / (float) 100;
        Pf = Math.round(Pf * 100) / (float) 100;
        Li = Math.round(Li * 100) / (float) 100;
        Pi = Math.round(Pi * 100) / (float) 100;
    }

    public float getOddInitial() {
        return Oi;
    }

    public float getOddFinal() {
        return Of;
    }

    public float getStackeInitial() {
        return Si;
    }

    public float getStakeFinal() {
        return Sf;
    }

    public float getProfitTotal() {
        return Pt;
    }

    public float getProfitInitial() {
        return Pi;
    }

    public float getProfitFinal() {
        return Pf;
    }

    public boolean isCorrect() {
        return correct;
    }
}
